<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="web-content.css" type="text/css">
    <link rel="stylesheet" href="test.css" type="text/css">
    <link rel="shortcut icon" href="chrome://ubiquity/skin/icons/favicon.ico" type="image/x-icon" />
    <title>Ubiquity Test Suite</title>
    <script type="text/javascript;version=1.7" src="resource://ubiquity/scripts/jquery.js"></script>
    <script type="text/javascript;version=1.7">
    
      Components.utils.import("resource://ubiquity/tests/framework.js");
      Components.utils.import("resource://ubiquity/tests/test_all.js");
      
      function startTestSuite() {
        var outputElement = document.getElementById("test-output");
        var suite = new TestSuite(new HtmlTestResponder(outputElement),
                                  window);
        suite.start();
      }
      
      function showSuccessfulTests() {
        var show = document.getElementById("show-tests-successful").checked;
        var tests = jQuery("#test-output .successful");
        if(show)
          tests.show();
        else
          tests.hide();
      }
      
      function showSkippedTests() {
        var show = document.getElementById("show-tests-skipped").checked;
        var tests = jQuery("#test-output .skipped");
        if(show)
          tests.show();
        else
          tests.hide();
      }
      
      function showFailedTests() {
        var show = document.getElementById("show-tests-failed").checked;
        var tests = jQuery("#test-output .failed");
        if(show)
          tests.show();
        else
          tests.hide();
      }
      
      function updateCounts() {
        function updateCountFor(type) {
          var count = jQuery("#test-output ." + type).length;
          if (count == 1)
            count = count + " test";
          else
            count = count + " tests";
          jQuery("#test-options label[for='show-tests-" + type + "'] .count").text("(" + count + ")");
        }
        updateCountFor("successful");
        updateCountFor("skipped");
        updateCountFor("failed");
      }
      
      jQuery(document).ready(function() {
        jQuery("#show-tests-successful").change(showSuccessfulTests);
        jQuery("#show-tests-skipped").change(showSkippedTests);
        jQuery("#show-tests-failed").change(showFailedTests);
        
        try {
          startTestSuite();
          jQuery("#tests-status").hide();
        } catch (e) {
          jQuery("#tests-status").text("Error running test suite: " + e);
        }
        
        showSuccessfulTests();
        showSkippedTests();
        showFailedTests();
        
        updateCounts();
      });
      
    </script>
  </head>
  <body>
    
    <h1>Ubiquity Test Suite</h1>
    
    <div id="test-options">
      <label for="show-tests-successful">
        <input type="checkbox" id="show-tests-successful" />
        Show successful tests
        <span class="count">(0 tests)</span>
      </label>
      <label for="show-tests-skipped">
        <input type="checkbox" id="show-tests-skipped" />
        Show skipped tests
        <span class="count">(0 tests)</span>
      </label>
      <label for="show-tests-failed">
        <input type="checkbox" id="show-tests-failed" checked="true" />
        Show failed tests
        <span class="count">(0 tests)</span>
     </label>
    </div>
    
    <div id="test-output"></div>
    <div id="tests-status">
      Tests are running...
    </div>
    
  </body>
</html>
